#include <iostream>
#include <string>
#include <memory>

using std::cout;
using std::endl;
using std::string;

class Computer
{
public:
    Computer()  {}

    void setBoard(const string &board)
    {
        _board = board;
    }

    void setDisplay(const string &display)
    {
        _display = display;
    }

    void showParamaters()
    {
        string param = "computer paramaters:\n";
        param += "\tBoard: " + _board + "\n";
        param += "\tDisplay: " + _display + "\n";
        param += "\tOs: " + _os + "\n";
        cout << param << endl;
    }
    virtual void setOs() = 0;
protected:
    string _board;
    string _display;
    string _os;
};

class MacBook : public Computer
{
public:
    void setOs() override
    {
        _os = "MAC OS x12";
    }
};

class Builder
{
public:
    virtual void buildBoard(const string &board) = 0;
    virtual void buildDisplay(const string & display) = 0;
    virtual void buildOs() = 0;
    virtual std::shared_ptr<Computer> build() = 0;
};

class MacBookBuilder : public Builder
{
public:
    MacBookBuilder()
        :_computer(new MacBook())
    {}

    void buildBoard(const string &board)
    {
        _computer->setBoard(board);
    }

    void buildDisplay(const string &display)
    {
        _computer->setDisplay(display);
    }

    void buildOs()
    {
        _computer->setOs();
    }

    std::shared_ptr<Computer> build()
    {
        return _computer;
    }
private:
    std::shared_ptr<Computer> _computer;
};

class Director
{
public:
    Director(Builder *builder) :_builder(builder) {}

    void construct(const string &board, const string &display)
    {
        _builder->buildBoard(board);
        _builder->buildDisplay(display);
        _builder->buildOs();
    }
private:
    std::shared_ptr<Builder> _builder;
};

int main()
{
    Builder *builder = new MacBookBuilder();
    std::unique_ptr<Director> director(new Director(builder));
    director->construct("华硕主板", "三星显示器");
    std::shared_ptr<Computer> computer = builder->build();
    computer->showParamaters();
    return 0;
}
